package com.github.florent37.materialimageanimation;

import com.github.florent37.materialimageloading.MaterialImageLoading;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;

public class MainAbility extends Ability {

    final static int DURATION = 4000;

    Image imageView;

    // Random ran = new Random();

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_main);

        imageView = (Image) findComponentById(ResourceTable.Id_image);
        imageView.setClickedListener((view)->{
            loadImage();
        });

        loadImage();
    }

    private void loadImage(){
        Picasso.get().load(ResourceTable.Media_materialimageloading_image_sample).fit().centerCrop().tag(this).into(imageView, new Callback() {

            @Override
            public void onSuccess() {
                MaterialImageLoading.animate(imageView).setDuration(DURATION).start();
            }

            @Override
            public void onError(Exception e) {

            }
        });
    }

}